package com.aaa.controller.scl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.scl.TestPlanScl;
import com.aaa.service.scl.TestPlanSclService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 心理健康SCL计划表(TestPlanScl)表控制层
 *
 * @author makejava
 * @since 2022-09-01 21:18:37
 */
@RestController
@RequestMapping("testPlanScl")
public class TestPlanSclController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanSclService testPlanSclService;

    @RequestMapping(value = "queryAllPlan.do")
    public Result queryAllPlan(PageSortEntity pageSortEntity, TestPlanScl testPlanScl) {
        List<TestPlanScl> testPlanSclList = testPlanSclService.queryAllPlan(testPlanScl, pageSortEntity);
        Page page = (Page) testPlanSclList;
        return success(page.getResult(), page.getTotal());
    }

    /**
     * 新增数据
     *
     * @param testPlanScl 实体
     * @return 新增结果
     */
    @RequestMapping(value = "saveTestPlanScl.do")
    public Result save(TestPlanScl testPlanScl) {
        TestPlanScl insert = testPlanSclService.insert(testPlanScl);
        if (ObjectUtil.isNotEmpty(insert)) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param testPlanScl
     * @return :  
     * @create by: Username 刘亦辰 
     * @description: 计划更新 
     * @create time: 2022/9/1 22:16
     */
    @RequestMapping(value = "updateTestPlanScl.do")
    public Result update(TestPlanScl testPlanScl) {
        TestPlanScl update = testPlanSclService.update(testPlanScl);
        if (ObjectUtil.isNotEmpty(update)) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param id
     * @return :  
     * @create by: Username 刘亦辰 
     * @description: 单个删除 
     * @create time: 2022/9/1 22:18
     */
    @RequestMapping(value = "delTestPlanScl.do")
    public Result deleteById(Integer id) {
        Boolean i = testPlanSclService.deleteById(id);
        if (i) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param null
     * @return :  
     * @create by: Username 刘亦辰 
     * @description:  批量删除
     * @create time: 2022/9/1 22:31
     */
    @RequestMapping(value = "delTestPlanSclBatch.do")
    public Result delTestPlanSclBatch(int[] id) {
        Integer integer = testPlanSclService.delTestPlanBatch(id);
        if (integer > 0) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * @param testPlanScl
     * @return :  
     * @create by: Username 刘亦辰 
     * @description: 重复性校验 
     * @create time: 2022/9/1 22:19
     */
    @RequestMapping(value = "repetitionName.do", method = RequestMethod.GET)
    public Result repetitionName(TestPlanScl testPlanScl) {
        Integer integer = testPlanSclService.repetitionName(testPlanScl);
        if (integer == 0) {
            return success("计划名称可用");
        }
        return fail("计划名称重复，不可用");
    }


}

